//
//  StarsView.m
//  UEAssistant
//
//  Created by mac on 2017/4/14.
//  Copyright © 2017年 youyixinxi. All rights reserved.
//

#import "StarsView.h"

@interface StarsView ()
{
    
    NSInteger               _num_level;
    NSMutableArray          *_stars;
}
@end

@implementation StarsView



- (instancetype)initWithFrame:(CGRect)frame level:(NSInteger)level{

    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        _num_level = level;
        [self setUI];
    }
    return self;
}

+ (instancetype)initWithFrame:(CGRect)frame level:(NSInteger)level{

    StarsView *star = [[self alloc]initWithFrame:frame level:level];
    return star;
}

- (void)setUI{

    [self addStars];
    
    switch (_num_level) {
        case 0:
        {
            //默认就是0星级
        }
            break;
        case 1:
        {
            [self reloadStarsLevelByIndex:1];
        }
            break;
        case 2:
        {
            [self reloadStarsLevelByIndex:2];
        }
            break;
        case 3:
        {
            [self reloadStarsLevelByIndex:3];
        }
            break;
        case 4:
        {
            [self reloadStarsLevelByIndex:4];
        }
            break;
        case 5:
        {
            [self reloadStarsLevelByIndex:5];
        }
            break;
  
        default:
            break;
    }
}

- (void)reloadStarsLevelByIndex:(int)index{

    for (int i = 0; i < index; i ++) {
        UIImageView *view = _stars[i];
        view.image = [UIImage imageNamed:@"star_"];
    }

}

- (void)addStars{

    _stars = [NSMutableArray array];
    for (int i = 0; i < 5; i++) {
        UIImageView *star = [[UIImageView alloc]initWithFrame:CGRectMake(18*Radio*i, 0, 15*Radio, 15*Radio)];
        star.image = [UIImage imageNamed:@"Star"];
        [self addSubview:star];
        [_stars addObject:star];
    }
}

@end
